{include file='common/doc'}
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" style="display: none;">
            <form  class="layui-form">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">昵称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="nickname" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">手机号</label>
                        <div class="layui-input-inline">
                            <input type="text"  name="phone" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">会员等级</label>
                        <div class="layui-input-inline">
                            <select name="member_level_id" id="">
                                <option value=""></option>
                                <option value=""></option>
                                {volist name="level" id="vo"}
                                <option value="{$vo.level_id}">{$vo.level_name}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">访问日期</label>
                        <div class="layui-input-inline">
                            <input type="text" name="last_time" class="layui-input" id="last_time">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-inline">
                            <select name="status">
                                <option value=""></option>
                                <option value="1">启用</option>
                                <option value="0">警用</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="search">搜索</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
        <script type="text/html" id="op_table">
            <?php echo  $operation['tool'] ?>
        </script>
        <div class="layui-card-body">
            <table id="table_list" lay-filter="table_list"></table>
            <template id="table_toolbar">
                <div class="layui-btn-group">
                    <?php echo  $operation['toolbar']; ?>
                </div>
            </template>

        </div>
    </div>
</div>
<div style="display:none;padding-top:30px;" id="form_template" >
    <form action="" class="layui-form" style="padding-top:30px;">
        <div class="layui-form-item">
            <label class="layui-form-label">api</label>
            <div class="layui-input-inline">
                <input type="text" name="token" disabled placeholder="token" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">token</label>
            <div class="layui-input-inline">
                <input type="text" name="token" disabled placeholder="token" autocomplete="off" class="layui-input">
            </div>
        </div>
    </form>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
</body>
<script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index' ,'table','laydate'] ,function () {
        var $ = layui.$
            ,form = layui.form
            ,table = layui.table;
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#last_time' //指定元素
            ,range: true
        });
        table.render({
            elem: '#table_list'
            ,height: 'full-50'
            ,toolbar: '#table_toolbar'
            ,skin:'line'
            ,url: 'read' //数据接口
            ,page: true //开启分页
            ,limit:20
            ,cols: [
                [ //表头
                    {type: 'checkbox' ,fixed: 'left'}
                    ,{type: 'numbers' ,fixed: 'left'}
                    ,{field: 'level_name' ,align: "center" ,title: '会员级别',style:'color:#01aaed;',fixed: 'left'}
                    ,{field: 'phone' ,align: "center" ,title: '手机号'}
                    ,{field: 'currency' ,align: "center" ,title: '流量币',sort:true,}
                    ,{field: 'pay_count' ,align: "center" ,title: '购买次数'}
                    ,{field: 'brokerage_price' ,align: "center" ,title: '佣金'}
                    ,{field: 'last_time' ,align: "center" ,title: '访问日期'}
                    ,{field: 'last_ip' ,align: "center" ,title: 'ip'}
                    ,{field: 'status' ,width:100,align: "center" ,title: '状态',event:'status',templet:function(d){
                        let btn =
                            [
                            '<input type="checkbox" name="status"  lay-skin="switch" lay-text="禁用|启用" >',
                             '<input type="checkbox" name="status" lay-skin="switch" lay-text="禁用|启用" checked>'
                            ];
                        return btn[d.status];
                    }}
                    ,{title: '操作',width:300,align: 'center' ,fixed: 'right' ,toolbar: '#op_table'}
                ]
            ]
        });
        //头工具栏事件
        table.on('toolbar(table_list)' ,function (obj) {
            let event = obj.event;
            var checkStatus = table.checkStatus(obj.config.id);
            if (event == 'search') {
                $('.layui-card-header').toggle('slow');
            }
        });

        table.on('tool(table_list)' ,function (obj) {

            let event = obj.event;
            if (event=='status'){
                    let field = {
                        'member_id':obj.data['member_id'],
                        'status':(obj.data['status']  ? 0: 1)
                    };
                let status = request({'url':'upd','data':field});

            }
            if (event == 'upd') {
                layer.open({
                    type: 1 ,
                    title: '用户编辑' ,
                    area: ['500px','500px'] ,
                    content: $('#form_template').html() ,
                    success: function (lay ,index) {
                        form.render();
                        form.val('form' ,obj.data);
                        form.on('submit(form_submit)' ,function (res) {
                            res.field['admin_id'] = obj.data['admin_id'];
                            let status = request({'url':'upd','data':res.field});
                            if(status){
                                table.reload();
                                layer.close(index);
                            }
                            return false;
                        });
                    }
                })
            }
            if (event == 'del') {
                $.post('del' ,obj.field ,function (res) {
                    obj.del();
                    layer.msg(res.msg);
                });
            }

        });
        /*搜索*/
        form.on('submit(search)' ,function (obj) {
            table.reload('table_list' ,{
                method: 'get' ,
                where: {where:obj.field},//设定异步数据接口的额外参数

            });
            return false;
        });
    });
</script>
</html>

